//
//  UITextField+Add.m
//  xiangjiang
//
//  Created by cong on 15/5/20.
//  Copyright (c) 2015年 王浩. All rights reserved.
//

#import "UITextField+Add.h"

@implementation UITextField (Add)

-(BOOL)addShakeAnimation
{
    if (self.text.length==0) {
        [self.layer addAnimation:[self shakeAnimation] forKey:nil];
        [self becomeFirstResponder];
        return YES;
    }else{
        return NO;
    }
}
//震动效果
-(CAKeyframeAnimation *)shakeAnimation
{
    CAKeyframeAnimation *shake = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
    shake.values = @[[NSValue valueWithCATransform3D:CATransform3DMakeTranslation(-5.0f, 0.0f, 0.0f)], [NSValue valueWithCATransform3D:CATransform3DMakeTranslation(5.0f, 0.0f, 0.0f)]];
    shake.autoreverses = YES;
    shake.repeatCount = 2.0f;
    shake.duration = 0.07f;
    return shake;
}

@end
